package cn.ytxy.ivos.application.controller;


import cn.ytxy.ivos.application.pojo.dto.ApplicationQuery;
import cn.ytxy.ivos.application.pojo.dto.ApplicationSaveParam;
import cn.ytxy.ivos.application.service.ApplicationService;
import cn.ytxy.ivos.base.response.JsonResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName ApplicationController
 * @Description TODO
 * @Author renhong~Deng
 * @Date 2025/5/13 9:20
 * @Version 1.0
 */

@Slf4j
@RestController
@RequestMapping("/v1/application/")
public class ApplicationController {

    @Autowired
    private ApplicationService applicationService;


    @PostMapping("/save")
    public JsonResult saveApplication(ApplicationSaveParam applicationSaveParam) {
        log.debug("保存申请单applicationSaveParam={}", applicationSaveParam);
        applicationService.save(applicationSaveParam);
        return JsonResult.ok();
    }

    @GetMapping("/select")
    public JsonResult selectApplication(ApplicationQuery applicationQuery) {
        log.debug("查询申请单ApplicationQuery={}", applicationQuery);
        return JsonResult.ok(applicationService.selectApplication(applicationQuery));
    }

    @PostMapping("/cancel/{id}")
    public JsonResult cancelApplicationById(@PathVariable Long id) {
        log.debug("撤销申请单id={}", id);
        applicationService.cancel(id);
        return JsonResult.ok();
    }

    @PostMapping("/distribute/{applicationId}/{vehicleId}")
    public JsonResult distribute(@PathVariable Long applicationId,  @PathVariable Long vehicleId){
        log.debug("分配车辆，applicationId={},vehicleId={}", applicationId, vehicleId);
        applicationService.distribute(applicationId, vehicleId);
        return JsonResult.ok();
    }

    @PostMapping("/back/{applicationId}/{vehicleId}")
    public JsonResult back(@PathVariable Long applicationId,  @PathVariable Long vehicleId){
        log.debug("还车，id={},vehicleId={}", applicationId, vehicleId);
        applicationService.back(applicationId, vehicleId);
        return JsonResult.ok();
    }
}
